package one.bugu.zookeeper.rpc.framework.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * Created with IntelliJ IDEA.
 * User: LangK
 * Created Date 2019/2/11
 * Time: 15:57
 * Description:
 */
public class SpringContextUtil implements ApplicationContextAware {

    /**
     * 以静态变量保存Spring ApplicationContext, 可在任何代码任何地方任何时候中取出ApplicaitonContext. 
     */
    private static ApplicationContext applicationContext;

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringContextUtil.applicationContext = applicationContext;
    }


    /**
     * @return ApplicationContext  
     */
    public static ApplicationContext getApplicationContext() {
        return SpringContextUtil.applicationContext;
    }
}
